home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / exampleCode / games / IndiZone / vroom / server.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  5.5 KB  |  227 lines

  1. /*
  2.  * Copyright (C) 1994, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17. #ifndef _SERVER_H_
  18. #define _SERVER_H_
  19.  
  20. #include "vroom.h"
  21.  
  22. #define    VROOM_GROUP        "224.0.1.2"
  23.  
  24. #define    VROOM_ALL_PLAYERS    (-1)
  25. #define    CLIENT_PACKET_BASE_ID    0x56524930
  26. #define    SERVER_PACKET_BASE_ID    0x56524f30
  27.  
  28. #define    CLIENT_P_SPEED        ( CLIENT_PACKET_BASE_ID | 0 )
  29. #define    CLIENT_P_INFO        ( CLIENT_PACKET_BASE_ID | 1 )
  30. #define    CLIENT_P_NAME        ( CLIENT_PACKET_BASE_ID | 2 )
  31. #define    CLIENT_P_MESSAGE    ( CLIENT_PACKET_BASE_ID | 3 )
  32.  
  33. #define    CLIENT_INFO_QUIT    1
  34. #define    CLIENT_INFO_JOIN    2
  35. #define    CLIENT_INFO_ACCEPT    3
  36. #define    CLIENT_INFO_UPDATE    4
  37. #define    CLIENT_INFO_COURSE_SEL    5
  38. #define    CLIENT_INFO_COURSE_ACK    6
  39. #define    CLIENT_INFO_COURSE_REQ    7
  40.  
  41. #define    CLIENT_TIMEOUT        (5.0f)    /* client must speak every 5 seconds */
  42. #define    CLIENT_UPDATE_FREQ    (2.0f)    /* client should speak every 2 secs */
  43.  
  44. #define    SERVER_TIMEOUT        (5.0f)    /* server must speak every 5 seconds */
  45.  
  46. #define    VROOM_SERVER_INPUT_PORT    5138
  47. #define    VROOM_SERVER_INPUT_SERVICE    "sgi-vroom-server"
  48.  
  49. /*
  50.  * Server input packets.
  51.  */
  52. typedef struct {
  53.     long    type ;
  54.     long    id ;
  55.     } inBasePacket ;
  56.  
  57. typedef struct {
  58.     long    type ;
  59.     long    id ;
  60.     long    playerNumber ;
  61.     long    steer ;
  62.     float    speed ;
  63.     } inSpeedPacket ;
  64.  
  65. typedef struct {
  66.     long    type ;
  67.     long    id ;
  68.     int    option ;
  69.     int    choice ;
  70.     } inInfoPacket ;
  71.  
  72. typedef struct {
  73.     long    type ;
  74.     long    id ;
  75.     char    name[VROOM_NAMELEN] ;
  76.     } inNamePacket ;
  77.  
  78. typedef struct {
  79.     long    type ;
  80.     long    id ;
  81.     char    msg[VROOM_MSGLEN] ;
  82.     } inMsgPacket ;
  83.  
  84. typedef union {
  85.     inBasePacket    base ;
  86.     inSpeedPacket    speed ;
  87.     inInfoPacket    info ;
  88.     inNamePacket    name ;
  89.     inMsgPacket    msg ;
  90.     } inputPacket ;
  91.  
  92.  
  93. /*
  94.  * Server output packets.
  95.  */
  96. typedef struct {
  97.     long    type ;
  98.     long    id ;
  99.     } outBasePacket ;
  100.  
  101. #define    SERVER_P_COURSE        ( SERVER_PACKET_BASE_ID | 0 )
  102. #define    SERVER_P_STATUS        ( SERVER_PACKET_BASE_ID | 1 )
  103. #define    SERVER_P_ACK        ( SERVER_PACKET_BASE_ID | 2 )
  104. #define    SERVER_P_RACE        ( SERVER_PACKET_BASE_ID | 3 )
  105. #define    SERVER_P_NAME        ( SERVER_PACKET_BASE_ID | 4 )
  106. #define    SERVER_P_MESSAGE    ( SERVER_PACKET_BASE_ID | 5 )
  107.  
  108. #define    ACK_ST_FAIL        0x01
  109. #define    ACK_ST_PLAYER        0x02
  110. #define    ACK_ST_CANDIDATE    0x03
  111. #define    ACK_ST_WAIT        0x04
  112. #define    ACK_ST_DROP        0x05
  113. #define    ACK_ST_COURSE_VOTE    0x06
  114. #define    ACK_ST_COURSE_CHOSEN    0x07
  115.  
  116. #define    SERVER_ST_INIT        0x00
  117. #define    SERVER_ST_COURSE_SEL    0x01
  118. #define    SERVER_ST_COURSE_ACK    0x02
  119. #define    SERVER_ST_PRE_TRIAL    0x03
  120. #define    SERVER_ST_TRIAL        0x04
  121. #define    SERVER_ST_POST_TRIAL    0x05
  122. #define    SERVER_ST_PRE_RACE    0x06
  123. #define    SERVER_ST_RACE        0x07
  124. #define    SERVER_ST_POST_RACE    0x08
  125. #define    SERVER_ST_RESULTS    0x09
  126. #define    SERVER_ST_QUIT        0x0a
  127.  
  128. typedef struct {
  129.     long    type ;
  130.     long    id ;
  131.     long    status ;
  132.     long    nPlayers ;
  133.     long    playerId[MAX_PLAYERS] ;
  134.     long    selection[MAX_PLAYERS] ;
  135.     } outStatusPacket ;
  136.  
  137. typedef struct {
  138.     long    type ;
  139.     long    id ;
  140.     long    mode ;
  141.     float    time ;
  142.     long    status[MAX_PLAYERS] ;
  143.     float    x[MAX_PLAYERS] ;
  144.     float    y[MAX_PLAYERS] ;
  145.     float    z[MAX_PLAYERS] ;
  146.     float    thetaDeg[MAX_PLAYERS] ;
  147.     float    roll[MAX_PLAYERS] ;
  148.     float    headingDeg[MAX_PLAYERS] ;
  149.     float    totalDis[MAX_PLAYERS] ;
  150.     float    indTime[MAX_PLAYERS] ;
  151.     float    desiredSpeed[MAX_PLAYERS] ;
  152.     float    lane[MAX_PLAYERS] ;
  153.     char    position[MAX_PLAYERS] ;
  154.     } outRacePacket ;
  155.  
  156. typedef struct {
  157.     char        id[4] ;
  158.     float        data[8] ;
  159.     } TrackDetailQuad ;
  160.  
  161. typedef struct {
  162.     long        type ;
  163.     long        id ;
  164.     long        courseId ;
  165.     long        size ;
  166.     int        nLaps ;
  167.     char        name[MAX_COURSE_NAME] ;
  168.     float        recLap ;
  169.     char        recLapOwner[VROOM_NAMELEN];
  170.     float        recRace ;
  171.     char        recRaceOwner[VROOM_NAMELEN];
  172.     TrackDetailQuad    detail[MAX_COURSE_SIZE/4] ;
  173.     } outCoursePacket ;
  174.  
  175. typedef struct {
  176.     long    type ;
  177.     long    id ;
  178.     long    targetId ;
  179.     long    status ;
  180.     long    data ;
  181.     } outAckPacket ;
  182.  
  183. typedef struct {
  184.     long    type ;
  185.     long    id ;
  186.     long    nPlayer ;
  187.     char    name[VROOM_NAMELEN] ;
  188.     } outNamePacket ;
  189.  
  190. typedef struct {
  191.     long    type ;
  192.     long    id ;
  193.     long    nPlayer ;
  194.     char    msg[VROOM_MSGLEN] ;
  195.     } outMsgPacket ;
  196.  
  197. typedef union {
  198.     outBasePacket    base ;
  199.     outStatusPacket    status ;
  200.     outRacePacket    race ;
  201.     outCoursePacket    course ;
  202.     outAckPacket    ack ;
  203.     outNamePacket    name ;
  204.     outMsgPacket    msg ;
  205.     } outputPacket ;
  206.  
  207. /* BEGIN PROTOTYPES server.c */
  208. int                 addToCourseList( outCoursePacket *packet ) ;
  209. void                broadcastMsgPacket( long nPlayer, char *msg ) ;
  210. void                checkPorts( void ) ;
  211. void                clearCourseList( void ) ;
  212. void                clientAckCourse( long id ) ;
  213. void                clientChoseCourse( long id, int choice ) ;
  214. void                closeServer( void ) ;
  215. outCoursePacket *   findCourseInList( char *name ) ;
  216. outCoursePacket *   findCourseInListById( long courseId ) ;
  217. int                 getPort( char *servName, int defaultPort ) ;
  218. char *              hostNameFromId( long id, int showIp ) ;
  219. int                 initLocalServer( void ) ;
  220. void                serverRun( void ) ;
  221. void                setServerCourseLabel( char *fmt, ... ) ;
  222. void                setServerForNextGame( void ) ;
  223. void                updateServerCourseLabel( int np ) ;
  224. /* END PROTOTYPES server.c */
  225.  
  226. #endif /* !_SERVER_H_ */
  227.